package Servlet;

import Damain.emp;
import Service.EmpUpdateService;
import Service.EmpUpdateServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * 修改员工
 */
@WebServlet(name = "EmpUpdateServlet", urlPatterns = "/empUpdateServlet")
public class EmpUpdateServlet extends HttpServlet {
    private EmpUpdateService empUpdateService = new EmpUpdateServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取到数据
        Map<String, String[]> map = request.getParameterMap();
        emp emp = new emp();
        try {
            BeanUtils.populate(emp, map);
            empUpdateService.Update(emp);

            request.getRequestDispatcher("/empListServlet").forward(request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
